<?php

namespace Seguridad\Controller\Service;

use Zend\Db\Adapter\Adapter;
use Componentes\Controller\UtilsArrayController;
use Seguridad\Model\Entity\Nodo;
use Seguridad\Controller\Service\GenericService;
use Seguridad\Model\Dao\NodoDAO;

//SERVICIO
class NodoService extends GenericService {

    /**
     * @var Zend\Db\Adapter\Adapter 
     */
    private $dbAdapter;
    private static $nodoService;

    /**
     * @param \Zend\Db\Adapter\Adapter $dbAdapter
     */
    private function __construct(Adapter $dbAdapter) {
        $this->dbAdapter = $dbAdapter;
    }

    public static function getInstance($adapter) {
        if (self::$nodoService == null) {
            self::$nodoService = new NodoService($adapter);
        }
        return self::$nodoService;
    }

    public function getNodoDao() {
        return NodoDAO::getInstance($this->dbAdapter);
    }

    /**
     * @param type $id
     * @return type
     */
    public function getRegistro($id) {
        $data = null;
        $success = false;
        $nodo = $this->obtenerNodoSegunId($id);
        if ($nodo->getId() != null) {
            $data[0] = $nodo->objectToArray();
            $success = true;
        }
        return UtilsArrayController::organizarOutput($success, $data, null);
    }

//------Retornan los objetos-------

    public function obtenerNodoSegunId($id) {
        $registros = $this->getNodoDao()->getRegistro($id);
        $data = UtilsArrayController::llenarData($registros);
        $nodo = new Nodo($data[0]);
        return $nodo;
    }

}
